Ext.define('AM.view.AddRoleView', {
		extend: 'Ext.grid.Panel',
		alias : 'widget.addRoleView',
		store : 'EmployeesStore',
		border:false,
		columnLines:true,
//		selModel : Ext.create('Ext.selection.CheckboxModel'), 
		selModel: {
	        injectCheckbox: 0,
	        mode: "SIMPLE"     //"SINGLE"/"SIMPLE"/"MULTI"
//	        checkOnly: true     //只能通过checkbox选择
   		 },
   		selType: "checkboxmodel",
    	dockedItems: [{
        xtype: 'pagingtoolbar',
        dock: 'bottom',
        store : 'EmployeesStore',
        displayInfo: true
    }],
		columns: [	
			        {text: '序号', dataIndex: 'id',width:0,align:'center'},
			        {text: '序号',  xtype: 'rownumberer',width:50,align:'center',tdCls:'background-color: #8EE5EE;'},
			        { text: '姓名',  dataIndex: 'name',  width:80,align:'center'},
			        { text: '人员角色',  dataIndex: 'rose.name',  width:80,align:'center'},
			        { text: '科室',dataIndex: 'dept', width:120,align:'center'},
			        { text: '操作', dataIndex: 'id',width:80,align:'center',renderer : function(data, cell, record, rowIndex,columnIndex){
			        	    var resultStr = "<div class='controlBtn'>" +     
                            "<a href='javascript:void("+record.get('id')+");'class='alarm_detail'onclick='addRole("+record.get('id')+")'>授权</a>&nbsp;&nbsp;&nbsp;&nbsp;"   
                            "</div>";     
         					 return resultStr;  
			       		  }
         	    	}
			     ],
			   tbar: [{
					     xtype : "combobox",
					     allowBlank:false,
					     labelAlign :"right",
						 fieldLabel: '选择科室',
						 id:"search_department1",
						 store :Ext.create('AM.store.TargetDepartStore'),
						 displayField: 'name',
						 valueField: 'id',
					     width:300
					  },
					  { xtype: 'button', text: '查询',handler: searchemp,icon : 'Ext/restful/images/find.png'
					  }
					]
})
function searchemp() {
		   var grid=this.ownerCt.ownerCt;
			var depart= Ext.getCmp('search_department1').getValue();
	       //此处为加载条件
		  grid.getStore().on('beforeload', function (store, options) {
		              var new_params = {serchdepartment:depart}
		                Ext.apply(store.proxy.extraParams, new_params);
		       });
	
		grid.getStore().reload();
					
}
function addRole(id) {
	  var grid=Ext.create('AM.view.AddRoleView');
		var empID=id;
		 var myform1= new Ext.form.Panel({
		 			bodyPadding: 25,
			        labelWidth : 65,
					   items: [{   
					   		      xtype : "combobox",
								  allowBlank:false,
								  emptyText:'请选择角色',
								  selectOnFocus:true,
								  forceSelection: true,
								  queryMode: 'local',
								  labelAlign :"right",
								  fieldLabel: '角色',
								  name: 'roseID',
								  store :"PowerStore",
								  displayField: 'name',
    							  valueField: 'id'
							}
//								{
//							    xtype: 'checkboxgroup',
//							    labelAlign :"right",
//						        fieldLabel: '数据权限',
//						        // Arrange checkboxes into two columns, distributed vertically
//						        columns: 3,
//						        vertical: true,
//						        items: [
//						            { boxLabel: '感染管理科 ', name: 'depar', inputValue: '1' },
//						            { boxLabel: '疾病预防控制处', name: 'depar', inputValue: '2'},
//						            { boxLabel: '医学工程部', name: 'depar', inputValue: '3' },
//						            { boxLabel: '计算机室', name: 'depar', inputValue: '4' },
//						            { boxLabel: '纪检办公室', name: 'depar', inputValue: '5' },
//						            { boxLabel: '宣传教育科', name: 'depar', inputValue: '6' },
//						            { boxLabel: '图书馆', name: 'depar', inputValue: '7' },
//						            { boxLabel: '党委办公室', name: 'depar', inputValue: '8' },
//						            { boxLabel: '院部办公室', name: 'depar', inputValue: '9' },
//						            { boxLabel: '医保办', name: 'depar', inputValue: '10' },
//						            { boxLabel: '护理部', name: 'depar', inputValue: '11' },
//						            { boxLabel: '医务部', name: 'depar', inputValue: '12' },
//						            { boxLabel: '科研办公室', name: 'depar', inputValue: '13'},
//						            { boxLabel: '离退休办公室', name: 'depar', inputValue: '14'},
//						            { boxLabel: '经济管理办公室', name: 'depar', inputValue: '15'}, 
//						            { boxLabel: '财务处', name: 'depar', inputValue: '16'},
//						            { boxLabel: '干保处', name: 'depar', inputValue: '17'}, 
//						            { boxLabel: '工会', name: 'depar', inputValue: '18'},
//						            { boxLabel: '门诊办', name: 'depar', inputValue: '19'},
//						            { boxLabel: '审计处', name: 'depar', inputValue: '20'},
//						            { boxLabel: '人事处', name: 'depar', inputValue: '21'},
//						            { boxLabel: '团委', name: 'depar', inputValue: '22'},
//						            { boxLabel: '医患办', name: 'depar', inputValue: '23'},
//						            { boxLabel: '职工保健室', name: 'depar', inputValue: '24'},
//						            { boxLabel: '教育处', name: 'depar', inputValue: '25'}
//						              
//						        ]
//							}
							]		        	
				        	       

		 })
			var win = new Ext.Window({
				title : "角色授权",
				width : 400,
				height : 200,
				frame:true,
				layout:'fit',
				items : [ myform1
							],
				buttons : [{
							text : "确定",
							handler : function() {
								win.getComponent(0).getForm().submit({
											 url : 'employees_addRole',
											 params :{ empID:empID},
											 success : function() {
											 	grid.getStore().reload();
												Ext.Msg.alert('提示', '授权成功');
												win.close();
											},
											failure : function() {
												Ext.Msg.alert('错误', '授权失败');
											},
											waitMsg : "请稍后，正在保存。。。。"
	
										});
							}
						}, {
							text : "重置",
							handler : function() {
								win.getComponent(0).getForm().reset();
							}
						}, {
							text : "取消",
							handler : function() {
												win.close();
											
							}
						}]
			});
		win.show();
}

